package com.yike.user.controller;

import com.yike.user.entity.PlatformUserRole;
import com.yike.user.service.PlatformUserRoleService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.PlatformUserRolePageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 平台用户角色 控制器
 *
 * @author Sakura
 * @since 2024-10-29
 */
@Slf4j
@RestController
@RequestMapping("/platform/userRole")
@Module("user")
@Api(value = "平台用户角色API", tags = {"平台用户角色"})
@ApiIgnore
public class PlatformUserRoleController extends BaseController {

    @Autowired
    private PlatformUserRoleService platformUserRoleService;

    /**
     * 添加平台用户角色
     */
    @PostMapping("/add")
    @OperationLog(name = "添加平台用户角色", type = OperationLogType.ADD)
    @ApiOperation(value = "添加平台用户角色", response = ApiResult.class)
    public ApiResult<Boolean> addPlatformUserRole(@Validated(Add.class) @RequestBody PlatformUserRole platformUserRole) throws Exception {
        boolean flag = platformUserRoleService.savePlatformUserRole(platformUserRole);
        return ApiResult.result(flag);
    }

    /**
     * 修改平台用户角色
     */
    @PostMapping("/update")
    @OperationLog(name = "修改平台用户角色", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改平台用户角色", response = ApiResult.class)
    public ApiResult<Boolean> updatePlatformUserRole(@Validated(Update.class) @RequestBody PlatformUserRole platformUserRole) throws Exception {
        boolean flag = platformUserRoleService.updatePlatformUserRole(platformUserRole);
        return ApiResult.result(flag);
    }

    /**
     * 删除平台用户角色
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除平台用户角色", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除平台用户角色", response = ApiResult.class)
    public ApiResult<Boolean> deletePlatformUserRole(@PathVariable("id") Long id) throws Exception {
        boolean flag = platformUserRoleService.deletePlatformUserRole(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取平台用户角色详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "平台用户角色详情", type = OperationLogType.INFO)
    @ApiOperation(value = "平台用户角色详情", response = PlatformUserRole.class)
    public ApiResult<PlatformUserRole> getPlatformUserRole(@PathVariable("id") Long id) throws Exception {
        PlatformUserRole platformUserRole = platformUserRoleService.getById(id);
        return ApiResult.ok(platformUserRole);
    }

    /**
     * 平台用户角色分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "平台用户角色分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "平台用户角色分页列表", response = PlatformUserRole.class)
    public ApiResult<Paging<PlatformUserRole>> getPlatformUserRolePageList(@Validated @RequestBody PlatformUserRolePageParam platformUserRolePageParam) throws Exception {
        Paging<PlatformUserRole> paging = platformUserRoleService.getPlatformUserRolePageList(platformUserRolePageParam);
        return ApiResult.ok(paging);
    }

}

